﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoPartsSearch.Domain.Abstract;
using AutoPartsSearch.Domain.Common;
using Griffin.MvcContrib.SqlServer.Localization;

namespace AutoPartsSearch.Web.Infrastructure.Cache.Localizations
{
    public class LocalizedViewsRepository : SqlLocalizedViewsRepository
    {
        private readonly int _timeToHoldCache = 5;

        public LocalizedViewsRepository(ILocalizationDbContext db, IConfigurationGetter configurationGetter)
            : base(db)
        {
            int value;
            if (int.TryParse(configurationGetter.GetConfigurationValue(Constants.LocalizationCacheInMinutes), out value))
            {
                this._timeToHoldCache = value;
            }
        }

        public override Griffin.MvcContrib.Localization.Views.ViewPrompt GetPrompt(System.Globalization.CultureInfo culture, Griffin.MvcContrib.Localization.Views.ViewPromptKey key)
        {
            CacheExecutor.Execute(() => base.GetPrompt(culture, key), _timeToHoldCache, culture.LCID, key.ToString());
            return base.GetPrompt(culture, key);
        }
    }
}